//
//  UIViewController+navigationBar.m
//  SYDrive
//
//  Created by CleverPeng on 2020/6/12.
//  Copyright © 2020 cmss. All rights reserved.
//

#import "UIViewController+navigationBar.h"

@implementation UIViewController (navigationBar)

/// 该方法可重写, 控制器是否显示导航, 只需要重写返回布尔值即可
- (BOOL)needHideNavigationBar {
    return NO;
}

/// 重写该方法, 以设置导航返回按钮
- (void)setUpNavigationLeftItem {
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(backClickedAction)];
}

/// 重写该方法, 告知哪个页面可以左滑关闭
- (BOOL)canLeftGestureRecognizerShouldBegin {
    return YES;
}

/// 重写该方法, 更改返回方式
-(void)backClickedAction {
    if (self.navigationController != nil && self.navigationController.viewControllers.count > 1) {
        // 应该可以判断出我被push出来的了
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}


@end
